package com.leetcode.demo3Solution.JianOffer;

import java.util.HashMap;

public class offer10 {
    /*青蛙跳台阶问题*/
    public static void main(String[] args) {
        Solution10 solution=new Solution10();
        solution.numWays(5);
        System.out.println("青蛙跳台阶:"+solution.numWays(10));

    }
}
class Solution2 {
    int x=0;
    public int numWays(int n) {
        if(n<=2) {
            return n;
        }
        return numWays(n-1)+numWays(n-2);
    }

}

class Solution10 {
    HashMap<Integer,Integer> map = new HashMap();
    public int numWays(int n) {
        if(n<=1) {
            return 1;
        }
        //先判断有没计算过
        if(map.containsKey(n)){
            //计算过，直接返回
            return map.get(n);
        }else{
            // 没有计算过，递归计算,并且把结果保存到map中
            map.put(n,(numWays(n-1) + numWays(n-2))% 1000000007);
            return map.get(n);
        }
    }

    /*public int numWays(int n) {
        if (n <= 1)
            return 1;
        int[] dp = new int[n + 1];
        dp[1] = 1;
        dp[2] = 2;
        for (int i = 3; i <= n; i++) {
            dp[i] = dp[i - 1] + dp[i - 2];
            dp[i] %= 1000000007;
        }
        return dp[n];*/
}





